﻿//-----------------------------------------------------------------
//
// @(#)$Id: ReBuilderOrder.aspx.cs,v 1.0 2013/12/13 17:57:14 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/13 17:57:14 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using ebay.Dal;
using ebay.Dal.CenterDB_BasTableAdapters;

public partial class UI_Orders_ReBuilderOrder : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        //T_ExpressShippingMethodsTableAdapter eAdapter = new T_ExpressShippingMethodsTableAdapter();
        //ddlDeliveryId.DataSource = eAdapter.GetData();
        //ddlDeliveryId.DataValueField = "Id";
        //ddlDeliveryId.DataTextField = "Delivery";
        T_ExpressShippingMethodsTableAdapter eAdapter = new T_ExpressShippingMethodsTableAdapter();
        ddlDeliveryId.DataSource = eAdapter.GetData();
        ddlDeliveryId.DataValueField = "EbayShippingMethods";
        ddlDeliveryId.DataTextField = "EbayShippingMethods";
        ddlDeliveryId.DataBind();
        ddlDeliveryId.Items.Insert(0, new ListItem("<--请选择-->", ""));

        //重发原因
        T_ReBuilderReasonTableAdapter rAdapter = new T_ReBuilderReasonTableAdapter();
        ddlreson.DataSource = rAdapter.GetData();
        //ddlreson.DataValueField = "ID";
        ddlreson.DataValueField = "ReBuilderReason";
        ddlreson.DataTextField = "ReBuilderReason";
        ddlreson.DataBind();
        ddlreson.Items.Insert(0, new ListItem("<--请选择-->", "0"));
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string orderId = Request["OrderId"];
            string ebayUserId = Request["EbayUserId"];
            if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId))
            {
                txtEbayUserId.Value = ebayUserId;
                txtOrderId.Value = orderId;

                //2012-7-27 sql添加的字段:City,County,PostalCode,Country
                string cmdText = @"Select top 1 a.BuyerName,a.AddressLine1,a.AddressLine2,a.City,a.County
                                        ,a.PostalCode,a.Country,a.DeliveryId,a.ReBuilderReson,a.PostageService 
                                    From Orders as a
                                    Where a.OrderId = @OrderId And a.EbayUserId = @EbayUserId";
                SqlParameter[] p = {
                                   new SqlParameter("@OrderId",SqlDbType.VarChar),
                                   new SqlParameter("@EbayUserId",SqlDbType.VarChar)
                                   };
                p[0].Value = orderId;
                p[1].Value = ebayUserId;

                DataTable table = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, cmdText, p);
                foreach (DataRow r in table.Rows)
                {
                    txtBuyerName.Value = r["BuyerName"].ToString();
                    ddlDeliveryId.Value = r["PostageService"].ToString();
                    textBoxAddresserLine1.Value = r["AddressLine1"].ToString();
                    textBoxAddresserLine2.Value = r["AddressLine2"].ToString();

                    //2012-7-27添加的字段
                    txtCity.Value = r["City"].ToString();
                    txtCountry.Value = r["Country"].ToString();
                    txtCounty.Value = r["County"].ToString();
                    txtPostalCode.Value = r["PostalCode"].ToString();
                }
                //重发次数
                //string cmdTextReCount = @"select COUNT(NewOrderId) as ReCount from  Orders Where EbayUserId = @EbayUserId And NewOrderId = @OrderId";
                //DataTable tableReCount = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, cmdTextReCount, p);
                //txtReCount.Value = Convert.ToString(tableReCount.Rows[0]["ReCount"]);
            }
        }
    }
}